/**
 *  Global authority directive
 *  用于细粒度权限控制, 通过v-auth指令控制元素的显示隐藏,根据locastorage中的AUTH__KEY__进行判断
 *  @Example v-auth = "authList.auth"
 */
import type { App, Directive, DirectiveBinding } from 'vue'

Vue.directive('auth', {
  bind: function (el, binding, vnode) {
    let authList = JSON.parse(localStorage.getItem(AUTH__KEY__))
    if (!authList) {
      el.parentNode.removeChild(el)
      return
    }
    let auth = binding.value
    if (!authList[auth]) {
      el.parentNode.removeChild(el)
    }
  }
})

// 计算1+1的函数
function add (a, b) {
  return a + b
}